package com.iaz.tech.tools.ai.neuron.exec;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iaz.tech.tools.ai.neuron.runtime.INeuronRuntimeAbility; 
import com.iaz.tech.tools.common.utils.UtilTools; 
import com.iaz.tech.tools.property.project.Project;
import com.iaz.tech.tools.uml.IUMLNeuronAble;
import com.iaz.tech.tools.uml.behavioral.usecase.impl.NeuronUseCase;
import com.iaz.tech.tools.uml.relationship.Relationship;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 用例代码生成器
 */
@EqualsAndHashCode(callSuper=false)
@Data
public class NeuronUseCaseCodeGenerator extends NeuronCodeGenerator {

    /**
     * 日志
     */
	private final static Logger logger = (Logger) LoggerFactory.getLogger(NeuronUseCaseCodeGenerator.class);  

    public NeuronUseCaseCodeGenerator() {
        super();
    }

    public NeuronUseCaseCodeGenerator(INeuronRuntimeAbility runtime) {
        super();
        this.setRuntime(runtime);
    }

    @Override
    public Relationship toRelationship(IUMLNeuronAble uml) throws Exception {
        throw new IllegalArgumentException("uml必须为Class");
    }
    
    /**
     * 生成用例代码
     * 1）最终生成的成果
     * 2）无需进行交换代码成果
     * 
     */
    @Override
    public String generateSourceCode(Project project, IUMLNeuronAble uml) {
        String result = "";
        try {
            if (uml == null){
                throw new IllegalArgumentException("uml不能为null");
            }

            if ( !(uml instanceof NeuronUseCase)){
                throw new IllegalArgumentException("uml必须为用例");
            }
            if ( this.getRuntime() == null) {
                throw new IllegalArgumentException("runtime不能为null");
            }
            /* 利用Use Case 生成所需代码 */
            NeuronUseCase useCase = (NeuronUseCase) uml;
            
            if (useCase.getSequence() != null){
                String name = useCase.getSequence().getName();
                if (UtilTools.IsNull(name)) {
                    throw new IllegalArgumentException("用例名称不能为null");
                }               

            }
        } catch (Exception e){
            logger.error("生成用例代码失败", e);
        }
        return result;
    }

}
